import errCallback from './error-tip'

export const fetchApi = async <dataType>(
	params: UniApp.RequestOptions
): Promise<{ code: number; data: dataType }> => {
	return new Promise(async (resolve, reject) => {
		const res = await uni.request(params)
		const data = (res && res.data) || {}
		const code = res && res.data && res.data.code
		const errAuth = await errCallback.init(code, data, params.url)
		if (errAuth.success) {
			resolve(data)
			return
		}
		reject({ res, errAuth })
	})
}

